package com.example.android.moretextview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
import android.widget.Scroller;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e("yongyi","最小的滑动有效距离"+ViewConfiguration.get(this).getScaledTouchSlop());

        gestureDetector.setOnDoubleTapListener(new OnDoubleTapListener() {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
                //严格的单击行为（只允许出现一次单击行为，如果触发了该事件，那么后面不可能再有单击事件。即只可能是单击，而不是双击中的一次。）
                return false;
            }

            @Override
            public boolean onDoubleTap(MotionEvent motionEvent) {
                //双击时触发（该方法不可与onSingleTapConfirmed()方法共存）
                return false;
            }

            @Override
            public boolean onDoubleTapEvent(MotionEvent motionEvent) {
                //表示发生了双击行为，在双击的期间，ACTION_DOWN、ACTION_MOVE和ACTION_UP都会触发该回调
                return false;
            }
        });

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        //获取滑动速度
//        VelocityTracker velocityTracker = VelocityTracker.obtain();
//        velocityTracker.addMovement(event);
//        velocityTracker.computeCurrentVelocity(1000);
//        float x = velocityTracker.getXVelocity();
//        float y = velocityTracker.getYVelocity();
//        Log.e("yongyi","VelocityTrackerX == "+x+"VelocityTrackerY=="+y);
//        velocityTracker.clear();
//        velocityTracker.recycle();
        return gestureDetector.onTouchEvent(event);
    }
    GestureDetector gestureDetector = new GestureDetector(new GestureDetector.OnGestureListener() {
        @Override
        public boolean onDown(MotionEvent motionEvent) {
            //手指轻轻触摸屏幕的一瞬间触发
            Log.e("yongyi","onDown");
            return false;
        }

        @Override
        public void onShowPress(MotionEvent motionEvent) {
            //手指轻轻触摸屏幕，尚未松开或拖动时触发
            Log.e("yongyi","onShowPress");
        }

        @Override
        public boolean onSingleTapUp(MotionEvent motionEvent) {
            //手指轻轻触摸屏幕后松开时触发
            Log.e("yongyi","onSingleTapUp");
            return false;
        }

        @Override
        public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
            //手指按下屏幕后拖动时触发
            Log.e("yongyi","onScroll");
            return false;
        }

        @Override
        public void onLongPress(MotionEvent motionEvent) {
            //长按屏幕时触发
            Log.e("yongyi","onLongPress");
        }

        @Override
        public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
            //	按下屏幕，快速滑动后松开时触发
            Log.e("yongyi","onFling");
            return false;
        }

    });
    Scroller scroller = new Scroller(this);


}
